package com.zhentao.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.dto.order.OrderStatisticsDto;
import com.zhentao.entity.order.OrderInfo;
import com.zhentao.entity.order.OrderStatistics;
import com.zhentao.mapper.OrderStatisticsMapper;
import com.zhentao.service.OrderInfoService;
import com.zhentao.mapper.OrderInfoMapper;
import com.zhentao.vo.order.OrderStatisticsVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Lenovo
* @description 针对表【order_info(订单)】的数据库操作Service实现
* @createDate 2024-09-03 14:12:24
*/
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo>
    implements OrderInfoService{
    @Resource
    private OrderStatisticsMapper orderStatisticsMapper;
    /**
     * 统计查询
     * @param orderStatisticsDto
     * @return
     */
    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        // 查询统计结果数据
        List<OrderStatistics> orderStatisticsList = orderStatisticsMapper.selectListStatistics(orderStatisticsDto);
        //日期列表
        List<String> dateList = orderStatisticsList.stream().map(orderStatistics -> DateUtil.format(orderStatistics.getOrderDate(), "yyyy-MM-dd")).collect(Collectors.toList());
        //统计金额列表
        List<BigDecimal> amountList = orderStatisticsList.stream().map(OrderStatistics::getTotalAmount).collect(Collectors.toList());
        // 创建OrderStatisticsVo对象封装响应结果数据
        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo() ;
        orderStatisticsVo.setDateList(dateList);
        orderStatisticsVo.setAmountList(amountList);
        // 返回数据
        return orderStatisticsVo;
    }
}




